<!-- Copyright 2008 (c) - GNU GPLv3 -->

<vexi xmlns:ui="vexi://ui" xmlns="org.vexigames.footywiz">
    <ui:box align="topleft" layout="place" width="13" height="16">
        <ui:box id="img" align="topleft" fill=":.image.player" shrink="true" />
        
        thisbox.anim = function() { return; }
        
        var wave;
        var still = function() {
            if (wave) {
                $img.x = (wave%2) ? -26 : -39;
                wave++;
                if (wave == 10) wave = 0;
            } else {
                var r = vexi.math.random();
                // normal
                if (0.85>r) $img.x = 0;
                // blink
                else if (0.98>r) $img.x = -13;
                // start waving
                else wave = 1;
            }
        }
        
        var count = 0;
        var run = function() {
            $img.x = -13*count;
            if ((++count)>3) count = 0;
        }
        
        thisbox.state ++= function(v) {
            cascade = v;
            switch(v) {
                case "still":
                    $img.y = 0;
                    wave = 0;
                    anim = still;
                    break;
                    
                case "run":
                    $img.y = -16;
                    count = 0;
                    anim = run;
                    break;
            }
        }
        
        
    </ui:box>
</vexi>